<?php 
class IMAP {
	var $im;
	var $username;
	var $pass;
		
	var $type;

	public function __construct($host,$username,$pass,$type) {
		$this->username=$username;
		$this->pass=$pass;
		$this->type=$type;
		$this->im=imap_open($host,$username,$pass);
	}
	
	public function __destruct() {
		imap_close($this->im);
	}
	
	
	//邮件信息
	public function info(){
		return $sta=imap_mailboxmsginfo($this->im);
	}
	
	
	public function sendMail($address,$title,$content_mail){
		require_once 'PHPMailer/class.phpmailer.php';
		$mail = new PHPMailer(); //建立邮件发送类
		$mail->IsSMTP();         // 使用SMTP方式发送
		$mail->SMTPAuth = true; // 启用SMTP验证功能
		$mail->Port=25;
		
		if($this->type==1){
			$mail->Host="smtp.163.com";
		}elseif($this->type==2){
			$mail->Host="smtp.126.com";
		}elseif($this->type==3){
			$mail->Host="smtp.qq.com";
		}elseif($this->type==4){
			$mail->Host="smtp.gmail.com";
		}elseif($this->type==5){
			$mail->Host="smtp.yahoo.com";
		}elseif($this->type==6){
			$mail->Host="smtp.souhu.com";
		}elseif($this->type==7){
			$mail->Host="smtp.sina.com.cn";
		}
		$mail->Username = $this->username;  // 邮局用户名(请填写完整的email地址)
		$mail->Password = $this->pass; // 邮局密码
		
		$mail->From = $this->username; //邮件发送者email地址
		$mail->FromName = '魔术师';  //用户昵称
		$mail->AddAddress($address, "亲爱的朋友");//收件人地址，可以替换成任何想要接收邮件的email信箱,格式是AddAddress("收件人email","收件人姓名")
		
		$mail->Subject =$title;  // "PHPMailer测试邮件"; //邮件标题
		$mail->Body = $content_mail;   //"Hello,这是测试邮件"; //邮件内容
		$mail->AltBody = "This is the body in plain text for non-HTML mail clients"; //附加信息，可以省略
		
		if(!$mail->Send())
		{
			echo "邮件发送失败. <p>";
			echo "错误原因: " . $mail->ErrorInfo;
			exit;
		}
		
		echo "邮件发送成功";
	}
	
	//收件箱数目
	public function getNum(){
		return $num=imap_num_msg($this->im);
	}
	
	//获取邮件正文
	public function getContent($uid){
		return  imap_fetchbody($this->im,$uid,FT_UID);
	}
	
	//获取邮件头部信息
	public function getHeader($uid){
		return imap_header($this->im,$uid);		
	}
	
	public function delete(){
	}
}
?>
